package com.internetCafes.spms.common.utils.entity.page;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页返回参数
 *
 * @param <T>
 * @author Zj
 */
@ApiModel
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageItemVO<T> {

    @ApiModelProperty(value = "数据列表")
    private List<T> records;
    @ApiModelProperty(value = "总数")
    private long total;
    @ApiModelProperty(value = "单页数量")
    private long size;
    @ApiModelProperty(value = "当前页数")
    private long current;
    @ApiModelProperty(value = "排序对象")
    private List<OrderItem> orders;

    @ApiModelProperty(value = "总页数")
    private long pages;

    public long getPages() {
        if (this.getSize() == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.getSize();
            if (this.getTotal() % this.getSize() != 0L) {
                ++pages;
            }
            return pages;
        }
    }

    public void setPages(long pages) {
        this.pages = pages;
    }
}
